package com.yunhe.tianhe.rentcars.service.client.Impl;/**
 * Created by Administrator on 2017/11/27 0027.
 */

import com.yunhe.tianhe.commons.dto.Pageable;
import com.yunhe.tianhe.rentcars.dao.client.BlackClientDao;
import com.yunhe.tianhe.rentcars.entity.client.BlackClient;
import com.yunhe.tianhe.rentcars.service.client.BlackClientService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @user yanxiu
 * @creat 2017-11-27 上午 9:35
 * @desc
 **/
@Service
public class BlackClientServiceImpl implements BlackClientService{

    @Autowired
    private BlackClientDao blackClientDao;

    @Override
    public void save(BlackClient blackClient) {
        blackClientDao.save(blackClient);
    }

    @Override
    public void deleteBatch(String ids) {
        String[] idArr = ids.split(",");
        for(String id:idArr){
            blackClientDao.delete(Long.valueOf(id));
        }

    }

    @Override
    public void update(BlackClient blackClient) {
        blackClientDao.update(blackClient);
    }

    @Override
    public Pageable<BlackClient> findPage(Integer offset, Integer limit, String name, String mobile, String idCard) {
        List<BlackClient> data = blackClientDao.findList(offset, limit, name, mobile, idCard);
        Pageable<BlackClient> pageable = new Pageable<>();
        Long count = blackClientDao.countLines(name, mobile, idCard);
        pageable.setPage(offset / limit + 1);
        pageable.setSize(limit);
        pageable.setTotal(count);
        pageable.setRows(data);
        return pageable;
    }

    @Override
    public BlackClient findOne(Long id) {
        return blackClientDao.findOne(id);
    }
}
